import { Component, OnInit } from '@angular/core';
import { JsonApiService } from "app/core/api/json-api.service"; //http请求配置引入
import {config} from '../../shared/smartadmin.config';

declare var $: any;
@Component({
	selector: 'sa-repairRecord',
	templateUrl: './repairRecord.component.html',
})
export class RepairRecordComponent implements OnInit {
	tableData:any[] = []; //table数据
	resultTableData:any[] = [] //客户端分页数据暂存
	totalCount:number = 0; //分页总条数
	curPage:number = 1; //分页当前页
	pageSize:number = 10; //内置的分页每页条数
	searchKey:string = ''; //搜索keyword
	userNameList:any[] = []; //用户数据集合
	userName:string = ''; //用户名
	apiNameList:any[] = []; //api数据集合
	apiName:string = ''; //api
	startTime:string = '';//开始时间
	endTime:string = '';	//结束时间
	userFlag:boolean = false;
	timeType:string = '0';
	isShow:boolean;
	recordType='';
	selectedCompanyId:string = '';
	selectedCompanyName:string = '';
	constructor(private jsonApiService: JsonApiService) {}
	
	
	// 接收子组件传递过来的数据 
	getSelectTableTime(time){
		this.startTime=time.startTime;
		this.endTime=time.endTime;
	} 
	//公司选中回调
	companySelected(data){
		this.selectedCompanyId = data.companyId;
		this.selectedCompanyName = data.companyName;
	}
	//刷新
	refresh(){
		this.load();
	}
	ngOnInit() {
		this.load();	
	}
	//查询
	search_data(){
		this.curPage = 1;
		this.load();
	}
	//加载list数据
	load() {
		var data = {
			pageSize:this.pageSize,
			nowPage:this.curPage,
			parameters:{
				startTime:this.startTime,
				endTime:this.endTime,
				companyId:this.selectedCompanyId,
				searchKey:this.searchKey,
				operation:this.recordType,
			}
		}
		let reqdata = 'gridPager='+JSON.stringify(data);
		this.jsonApiService.http('fixdatalog/logforpage.html', reqdata).subscribe(result => {
			this.resultTableData=result.exhibitDatas;
			this.totalCount=result.recordCount;
		})
	}
	table_search(){
		this.curPage = 1;
		this.searchKey = common.stringTrim(this.searchKey);
		this.load();
	}
	//删除所选时间
	del_date(){
		this.startTime = '';
		this.endTime ='';
	}
	client_pages(start,length){
		this.resultTableData = this.tableData.slice(start,start+length);
	}
	//分页回调
	paginate(e){
		this.curPage = e.page+1;
		this.pageSize = e.rows;
		this.load();
	}
}